package cn.itlaobing.eshop.dao;/**
 * Created by 1223 on 2017/11/13.
 */

import com.alibaba.druid.pool.DruidDataSource;

import javax.sql.DataSource;

/**
 * 类名：
 * 描述：
 * 作者：陈志凯
 * 时间：2017/11/13
 */
public class BaseDao {
    private static final String DB_URL="jdbc:mysql://127.0.0.1:3306/itlaobing_eshop?characterEncoding=utf8";
    private static final String DB_USER_NAME="root";
    private static final String DB_PASSWORD="root";
    private static final String DB_DRIVER_CLASS_NAME="com.mysql.jdbc.Driver";

    private DataSource dataSource=null;

    /**
     * 创建连接池
     * @throws DataSource
     */
    protected DataSource getDataSource(){
        if(dataSource!=null){
            return dataSource;
        }
        DruidDataSource dataSource=new DruidDataSource();
        dataSource.setUrl(DB_URL);
        dataSource.setUsername(DB_USER_NAME);
        dataSource.setPassword(DB_PASSWORD);
        dataSource.setDriverClassName(DB_DRIVER_CLASS_NAME);
        this.dataSource=dataSource;
        return dataSource;
    }

}
